﻿using System;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using DMS.Base;

namespace DMS.Business.Modules.SystemManage
{
    public class ChangeLogHelper
    {
        public static ChangeLogHelper Instance = new ChangeLogHelper();
        private ChangeLogHelper() { }

        public int CountLog(string condition)
        {
            string countSql = String.Format(@"select count(*) num
	                                            from ORG_UserChangeLog n 
                                            where 1 = 1                                           
                                            {0}", condition);
            DbCommand command = DBHelper.Instance.GetSqlStringCommand(countSql);
            DataSet ds = DBHelper.Instance.ExecuteDataSet(command);
            return Convert.ToInt32(ds.Tables[0].Rows[0]["num"]);
        }

        public DataSet ListLog(int pageSize, int pageIndex, int total, string condition)
        {
            string sql = String.Format(@"select *, case when type = 1 then '新入职' when type = 2 then '部门调动' when type = 3 then '离职' end ChangeType
	                                        from ORG_UserChangeLog n 
                                        where 1 = 1 
                                        {0} order by Time desc", condition);
            SqlCommand command = new SqlCommand(sql, new SqlConnection(DBHelper.Instance.ConnectionString));
            SqlDataAdapter dataAdapter = new SqlDataAdapter(command);
            DataSet ds = new DataSet();
            dataAdapter.Fill(ds, pageIndex - 1, pageSize, "Table1");
            return ds;
        }
    }
}
